$(function() {
    $('#com_bottom').load('../assets/public/html/PublicBottom.html');

    //职业类型
    $('.search_con_type').mouseover(function() {
        $('.search_con_type_ul').show();
        $('.search_con_type_ul').mouseenter(function() {
            $('.search_con_type_ul').show();
            $('.search_con_type_ul > li').click(function() {
                let SearchConType = $(this).text();
                $('.search_con_type_con_span').text(SearchConType);
                $('.search_con_type_ul').hide();
            });
        });
    }).mouseleave(function() {
        $('.search_con_type_ul').hide();
    });

    // 全部城市
    $('.search_con_jobadd_right').mouseover(function() {
        $('.search_con_jobadd_right > span').css('color', '#FF511C');
        $('.search_con_jobadd_right_qianimg').hide();
        $('.search_con_jobadd_right_houimg').show();
    }).mouseleave(function() {
        $('.search_con_jobadd_right > span').css('color', '#666');
        $('.search_con_jobadd_right_houimg').hide();
        $('.search_con_jobadd_right_qianimg').show();
    });

    //学历要求
    $('.search_con_jobtype_education').mouseover(function() {
        $('.search_con_education_Module_II').show();
        $('.search_con_education_Module_II').mouseenter(function() {
            $('.search_con_education_Module_II').show();
            $('.search_con_education_Module_II > li').click(function() {
                let SearchConJobtypeEducation = $(this).text();
                $('.search_con_jobtype_education > span').text(SearchConJobtypeEducation);
                $('.search_con_education_Module_II').hide();
            });
        });
    }).mouseleave(function() {
        $('.search_con_education_Module_II').hide();
    });

    //工作经验
    $('.search_con_jobtype_experience').mouseover(function() {
        $('.search_con_experience_Module_II').show();
        $('.search_con_experience_Module_II').mouseenter(function() {
            $('.search_con_experience_Module_II').show();
            $('.search_con_experience_Module_II > li').click(function() {
                let SearchConJobtypeExperience = $(this).text();
                $('.search_con_jobtype_experience > span').text(SearchConJobtypeExperience);
                $('.search_con_experience_Module_II').hide();
            });
        });
    }).mouseleave(function() {
        $('.search_con_experience_Module_II').hide();
    });

    //薪资范围
    $('.search_con_jobtype_Range').mouseover(function() {
        $('.search_con_Range_Module_II').show();
        $('.search_con_Range_Module_II').mouseenter(function() {
            $('.search_con_Range_Module_II').show();
            $('.search_con_Range_Module_II > li').click(function() {
                let SearchConJobtypeRange = $(this).text();
                $('.search_con_jobtype_Range > span').text(SearchConJobtypeRange);
                $('.search_con_Range_Module_II').hide();
            });
        });
    }).mouseleave(function() {
        $('.search_con_Range_Module_II').hide();
    });

    //企业规模
    $('.search_con_jobtype_scale').mouseover(function() {
        $('.search_con_scale_Module_II').show();
        $('.search_con_scale_Module_II').mouseenter(function() {
            $('.search_con_scale_Module_II').show();
            $('.search_con_scale_Module_II > li').click(function() {
                let SearchConJobtypeRange = $(this).text();
                $('.search_con_jobtype_scale > span').text(SearchConJobtypeRange);
                $('.search_con_scale_Module_II').hide();
            });
        });
    }).mouseleave(function() {
        $('.search_con_scale_Module_II').hide();
    });

    //融资阶段
    $('.search_con_jobtype_stage').mouseover(function() {
        $('.search_con_stage_Module_II').show();
        $('.search_con_stage_Module_II').mouseenter(function() {
            $('.search_con_stage_Module_II').show();
            $('.search_con_stage_Module_II > li').click(function() {
                let SearchConJobtypeRange = $(this).text();
                $('.search_con_jobtype_stage > span').text(SearchConJobtypeRange);
                $('.search_con_stage_Module_II').hide();
            });
        });
    }).mouseleave(function() {
        $('.search_con_stage_Module_II').hide();
    });

    //清空筛选条件
    $('.search_con_jobtype_right').click(function() {
        $('.search_con_jobtype_education > span').text('学历要求');
        $('.search_con_jobtype_experience > span').text('工作经验');
        $('.search_con_jobtype_Range > span').text('薪资范围');
        $('.search_con_jobtype_scale > span').text('企业规模');
        $('.search_con_jobtype_stage > span').text('融资阶段');
    });

    //热门搜索
    function PopSeaSearch() {
        let Hot_Search = Interceptor('/hotSearch', 'post');
        for (i = 0; i <= Hot_Search.data.length - 1; i++) {
            const HotSearchTitle = `
                <li>
                    <a>${Hot_Search.data[i].official}</a>
                </li>
            `
            $('.search_con_hot > ul').append(HotSearchTitle);
        }
        $('.search_con_hot > ul > li > a').click(function() {
            let SearchC_onHot_a = $(this).text();
            $('#nav_search').val(SearchC_onHot_a);
        });
        if (Hot_Search.data == 0) {
            $('.search_con_hot').hide();
        } else {
            $('.search_con_hot').show();
        }
    }
    PopSeaSearch();


    //热门城市
    function HotCity() {
        let Hot_City = Interceptor('/hotCity', 'post');
        for (i = 0; i <= Hot_City.data.length - 1; i++) {
            const HotCityTitle = `
                <li>
                    <span>${Hot_City.data[i].cri_short_name}</span>
                </li>
            `
            $('.search_con_jobadd > ul').append(HotCityTitle);
        }
        $('.search_con_jobadd > ul > li > span').click(function() {
            let SearchConJobadd_span = $(this).text();
            $('.search_con_jobadd_left > span').text(SearchConJobadd_span);
        });
    }
    HotCity();

    //地区
    function ProLevel() {
        let Provincial_Level = Interceptor('/getProvincial', 'post');
        $('.SearchPage_region_remen').html('');
        for (i = 0; i <= Provincial_Level.data.length - 1; i++) {
            const ProvincialLevelTitle = `
                        <a onclick="SearchPageRegion_A($(this).text())">${Provincial_Level.data[i].cri_name}</a>
                    `
            $('.SearchPage_region_remen').append(ProvincialLevelTitle);
        }
    }

    SearchPageRegion_A = function(SeaPagReg) {
        $('.search_con_add_con_span').text(SeaPagReg);
        $('.search_con_add_con_span').attr("title", SeaPagReg);
        $('#SearchPage_region').css('display', 'none');
    };

    //省级行政区
    $('.search_con_add').click(function() {
        $('#SearchPage_region').css('display', 'block');
        ProLevel();
    });
    $('.search_con_jobadd_right').click(function() {
        $('#SearchPage_region').css('display', 'block');
        ProLevel();
    });

    //全国
    //市级行政区
    $('.search_con_jobadd_left').click(function() {
        let ProvincialLevel = $('.search_con_add_con > span').text(); //省级
        if (ProvincialLevel == "地区") {
            $('#SearchPage_region').css('display', 'block');
            ProLevel();
        } else {
            $('#SearchPage_region_one').css('display', 'block');
            MunLevel();
        };

        function MunLevel() {
            let Municipal_Level = Interceptor('/getUrban', 'post', {
                'province': ProvincialLevel, //上传省级行政区
            });
            $('.region_one_remen').html('');
            for (i = 0; i <= Municipal_Level.data.length - 1; i++) {
                const MunicipalLevelTitle = `
                    <a onclick="SearchMunLevel_A($(this).text())">${Municipal_Level.data[i].cri_name}</a>
                `
                $('.region_one_remen').append(MunicipalLevelTitle);
            }
        };
        SearchMunLevel_A = function(SeaMunLev) {
            $('.search_con_jobadd_left > span').text(SeaMunLev);
            $('.search_con_jobadd_left > span').attr("title", SeaMunLev);
            $('#SearchPage_region_one').css('display', 'none');
            $('#search_con_jobadd_town').show();
            $('#search_con_town').show();

            //不限&&不限
            //县级行政区
            let MunicipalLevel = $('.search_con_jobadd_left > span').text(); //市级

            function coulevel() {
                let county_level = Interceptor('/getTown', 'post', {
                    'urban': MunicipalLevel, //上传市级行政区
                });
                $('.search_con_town > ul').html('');
                for (i = 0; i <= county_level.data.length - 1; i++) {
                    const CountyLevelTitle = `
                        <li>
                            <span onclick="SearchCoulevel_A($(this).text())">${county_level.data[i].cri_name}</span>
                        </li>
                    `
                    $('.search_con_town > ul').append(CountyLevelTitle);
                }
            }
            SearchCoulevel_A = function(SeaCoulev) {
                console.log(SeaCoulev);
                $('.search_con_jobadd_town_left > span').text(SeaCoulev);
                $('.search_con_jobadd_town_left > span').attr("title", SeaCoulev);
                $('.search_con_town_left > span').text(SeaCoulev);
                $('.search_con_town_left > span').attr("title", SeaCoulev);
            };
            coulevel();
        };
    });

    //热门职位
    function HotPosition() {
        let Hot_Official = Interceptor('/getHotOfficial', 'post');
        $('.search_con_three_Hotmove > ul').html('');
        for (i = 0; i <= Hot_Official.data.length - 1; i++) {
            let HotOfficialTitle = `
                <li>
                    <a href="PositionDetailsPage.html?official_id=${Hot_Official.data[i].official_id}">
                        <img src="${Hot_Official.data[i].company_logo}" alt="" class="Hotmove_title_touimg">
                        <h5 title="${Hot_Official.data[i].official}">${Hot_Official.data[i].official}</h5>
                        <img src="https://19jwshow.oss-cn-shenzhen.aliyuncs.com/recruit/icon/right_icon-location.png" alt="" class="Hotmove_title_iconimg">
                        <span class="Hotmove_title_add">${Hot_Official.data[i].company_area}</span>
                        <span class="Hotmove_title_xin">${Hot_Official.data[i].range_money}</span>
                        <p>${Hot_Official.data[i].company_name}<span class="Hotmove_title_stu">${Hot_Official.data[i].education}</span></p>
                    </a>
                </li>
            `
            $('.search_con_three_Hotmove > ul').append(HotOfficialTitle);
        }
        if (Hot_Official.data == 0) {
            $('.search_con_three_Hotmove_Changeit').hide();
            $('#search_con_three_Hotmove_no').show();
            $('.search_con_three_Hotmove').css('height', '120px');
        } else {
            $('#search_con_three_Hotmove_no').hide();
            $('.search_con_three_Hotmove_Changeit').show();
        }
    };
    HotPosition();
    //跳一跳
    $('.search_con_three_Hotmove_Changeit').click(function() {
        HotPosition();
    });


    //热门公司
    function PopCom() {
        let Hot_Company = Interceptor('/getHotCompany', 'post');
        for (i = 0; i <= Hot_Company.data.length - 1; i++) {
            let HotCompanyTitle = `
                <li>
                    <a href="CompanyIntroduce.html?company_id=${Hot_Company.data[i].company_id}">
                        <img src="${Hot_Company.data[i].company_logo}" alt="">
                        <span class="three_hot_con_first">${Hot_Company.data[i].company_name}</span>
                        <span class="three_hot_con_cen">${Hot_Company.data[i].type}</span>
                        <span class="three_hot_con_last">${Hot_Company.data[i].range_money}</span>
                    </a>
                </li>
            `
            $('.search_con_three_hot > ul').append(HotCompanyTitle);
        }
        if (Hot_Company.data == 0) {
            $('.search_con_three_hot').css({
                'top': '160px',
                'height': '120px'
            });
            $('#search_con_three_hot_no').show();
            $('#search').css('height', '1400px');
        } else {
            $('.search_con_three_hot').css('top', '572px');
            $('#search_con_three_hot_no').hide();
        }
    };
    PopCom();

    //职业 || 公司
    $('.search_con_Interface').mouseover(function() {
        $('.search_con_Interface_ul').show();
        $('.search_con_Interface_ul').mouseenter(function() {
            $('.search_con_Interface_ul').show();
            $('.search_con_Interface_ul > li').click(function() {
                let SearchConInterface = $(this).text();
                $('.search_conInterface_con_span').text(SearchConInterface);
                $('.search_con_Interface_ul').hide();
            });
        });
    }).mouseleave(function() {
        $('.search_con_Interface_ul').hide();
    });

    //获取搜索内容
    var NavSea = $(location).attr("href");
    var NavSeaTetle = NavSea.split("=");
    var Navseach_tetle = NavSeaTetle[1];
    var Nav_seach_tetle = decodeURI(Navseach_tetle);
    if (Nav_seach_tetle != "undefined") {
        $('#nav_search').val(Nav_seach_tetle);
        PositionDefaultoff();
    };

    //搜索内容
    $('.search_con_button').click(() => {
        var Coninterface = $('.search_conInterface_con_span').text();
        var NavSearch = $('#nav_search').val();
        if (Coninterface == "职业" && NavSearch == 0) {
            $('.search_con_three_compeny').html('');
            PositionDefault();
        } else if (Coninterface == "职业") {
            $('.search_con_three_compeny').html('');
            PositionDefaultoff();
        } else if (Coninterface == "公司" && NavSearch == 0) {
            $('.search_con_three_personal').html('');
            CompanyDefault();
        } else if (Coninterface == "公司") {
            $('.search_con_three_personal').html('');
            CompanyDefaultoff();
        }
    });
    PositionDefault();

    function PositionDefault() {
        var SearchPosition = Interceptor('/searchOfficial', 'post');
        console.log(SearchPosition);
        if (SearchPosition.message = '返回所有职位' && SearchPosition.data.data.length == 0) {
            $('#page').hide();
            $('.search_con_three_compeny').html('');
            $('.search_con_three_personal').html('');
            $('.search_con_no_search_content_no').show();
        } else {
            $('.search_con_no_search_content').hide();
            $('.search_con_no_search_content_no').hide();
            var rowCount = SearchPosition.data.data.length; //条数
            var pageSi = Math.ceil(rowCount / 8); //总页数
            $('#page').html('');
            $('#page').show();
            if (rowCount == 1) {
                var Count = 2;
            } else {
                var Count = rowCount;
            }
            var nowpage = setPage(1, Count);
            var begin = nowpage * 8 - (nowpage * 8);
            if (nowpage < pageSi) {
                var end = nowpage * 8 - 1;
            } else {
                var end = rowCount - 1;
            }
            SearchPos(begin, end);
        }

        function setPage(nowpage, totalCount) { //nowpage:当前页数  totalCount：数据总条数
            let pageSize = Math.ceil(totalCount / 8); //总页数
            let showSize = pageSize; //显示的页数
            let maxPage = pageSize;
            let oldPage = 1;
            if (showSize <= pageSize) {
                maxPage = showSize;
            }
            if (nowpage > pageSize) {
                nowpage = pageSize;
            }
            if (nowpage < 1) {
                nowpage = 1;
            }
            $("#page").append('<ul><li>&laquo;</li>');
            if (nowpage > Math.ceil(showSize / 2)) {
                if (nowpage <= pageSize - 2 && nowpage >= 3) {
                    for (let i = nowpage - 2; i <= eval(nowpage + "+2"); i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                } else if (nowpage == pageSize - 1) {
                    for (let i = nowpage - 3; i <= eval(nowpage + "+1"); i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                } else {
                    for (let i = nowpage - 4; i <= nowpage; i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                }
            } else {
                for (let i = 1; i <= showSize; i++) {
                    if (i == nowpage) {
                        $("#page ul").append('<li class="active">' + i + '</li>');
                    } else {
                        $("#page ul").append('<li>' + i + '</li>');
                    }
                }
            }
            oldPage = nowpage;
            $("#page ul").append('<li>&raquo;</li></ul>')
            $("#page ul li").click(function() {
                nowpage = $(this).text();
                if ($(this).text() == "«") {
                    $("#page").empty()
                    setPage(Math.ceil(oldPage - 1), totalCount);
                    $(this).siblings("li").removeClass("active");
                } else if ($(this).text() == "»") {
                    $("#page").empty()
                    setPage(Math.ceil(oldPage + 1), totalCount);
                    $(this).siblings("li").removeClass("active");
                } else if (showSize >= pageSize) {
                    $(this).attr("class", "active");
                    $(this).siblings("li").removeClass("active");
                } else if ($(this).text() <= Math.ceil(showSize / 2)) {
                    $(this).attr("class", "active");
                    $(this).siblings("li").removeClass("active");
                } else {
                    $("#page").empty()
                    setPage($(this).text(), totalCount);
                    $(this).siblings("li").removeClass("active");
                }
            })

            return nowpage;

            //如果跳到第1页，则开始就是i=0 (1-1),结束 = 7  (1*8-1)
            //如果跳到第2页，则开始就是i=8 (1*8),结束 = 15 (2*8-1)
            //如果跳到第3页，则开始就是i=16(2*8),结束 = 23 (3*8-1)
        }

        function SearchPos(start, hops) { //职位渲染
            $('.search_con_three_personal').html('');
            $('.search_con_three_compeny').html('');
            for (let i = start; i <= hops; i++) {
                const SearchTetle = `
                    <a href="PositionDetailsPage.html?official_id=${SearchPosition.data.data[i].official_id}">
                        <div class="personal_con">
                            <div class="personal_con_shang">
                                <div class="personal_con_means">
                                    <div class="personal_con_means_one">
                                        <h5>${SearchPosition.data.data[i].official}</h5>
                                        <img src="https://19jwshow.oss-cn-shenzhen.aliyuncs.com/recruit/icon/right_icon-location.png" alt="">
                                        <span title="${SearchPosition.data.data[i].off_area}" class="personal_con_means_one_fc">${SearchPosition.data.data[i].off_area}</span>
                                        <span>${SearchPosition.data.data[i].job_money}薪</span>
                                    </div>
                                    <div class="personal_con_means_two">
                                        <span>${SearchPosition.data.data[i].education}及以上</span>
                                        <span>5 - 8 年</span>
                                        <span>${SearchPosition.data.data[i].wordweek}天/周</span>
                                    </div>
                                    <div class="personal_con_means_three">
                                        <img src="${SearchPosition.data.data[i].header}" alt=" ">
                                        <span>${SearchPosition.data.data[i].username}</span>
                                    </div>
                                </div>
                                <div class="personal_con_company">
                                    <div class="personal_con_company_left">
                                        <p><a href="CompanyIntroduce.html?company_id=${SearchPosition.data.data[i].company_id}" id="personal_con_Company_name">${SearchPosition.data.data[i].company_name}</a><span class="personal_con_company_left_span">已上市</span></p>
                                        <p>${SearchPosition.data.data[i].type}</p>
                                        <p>${SearchPosition.data.data[i].com_official}人以上</p>
                                    </div>
                                    <div class="personal_con_company_right">
                                        <img src="${SearchPosition.data.data[i].company_logo}" alt="">
                                    </div>
                                </div>
                            </div>
                            <div class="personal_con_xia">
                                <ul>
                                    <li>${SearchPosition.data.data[i].requirement}</li>
                                    <li></li>
                                    <li></li>
                                    <li></li>
                                </ul>
                                <ul>
                                    <li>${SearchPosition.data.data[i].company_welfare}</li>
                                    <li></li>
                                    <li></li>
                                    <li></li>
                                </ul>
                            </div>
                        </div>
                    </a>
                `
                $('.search_con_three_personal').append(SearchTetle);
            }
        }
    }

    function PositionDefaultoff() {
        let NavSearch = $('#nav_search').val(); //必
        let SearchEducation = $('.search_con_jobtype_education > span').text();
        let SearchExperience = $('.search_con_jobtype_experience > span').text();
        let SearchScale = $('.search_con_jobtype_scale > span').text();
        let SearchType = $('.search_con_type_con_span').text();
        let SearchSalary = $('.search_con_jobtype_Range > span').text();
        let SearchProLevel = $('.search_con_add_con_span').text(); //传省
        let SearchMunLevel = $('.search_con_jobadd_left > span').text(); //传市
        let SearchCoulevel = $('.search_con_jobadd_town_left > span').text(); //传镇
        if (SearchEducation == "学历要求") {
            var Education = "";
        } else {
            var Education = SearchEducation;
        }
        if (SearchExperience == "工作经验") {
            var Experience = "";
        } else {
            var Experience = SearchExperience;
        }
        if (SearchScale == "企业规模") {
            var Scale = "";
        } else {
            var Scale = SearchScale;
        }
        if (SearchType == "职业类型") {
            var type = "";
        } else {
            var type = SearchType;
        }
        var page = "";
        if (SearchSalary == "薪资范围") {
            var money = "";
        } else {
            var money = SearchSalary;
        }
        if (SearchProLevel == "地区") {
            var Pro = "";
        } else {
            var Pro = SearchProLevel;
        }
        if (SearchMunLevel == "全国") {
            var Mun = "";
        } else {
            var Mun = SearchMunLevel;
        }
        if (SearchCoulevel == "不限") {
            var Cou = "";
        } else {
            var Cou = SearchCoulevel;
        }
        let SearchPosition = Interceptor('/searchOfficial', 'post', {
            'searchValue': NavSearch, //输入搜索内容 搜索学历，职位，公司
            'searchEducation': Education,
            'searchBackground': Experience,
            'searchPeople': Scale,
            'searchType': type,
            'page': page,
            'searchMoney': money,
            'province': Pro,
            'urban': Mun,
            'town': Cou
        });
        if (SearchPosition.message == '没有该内容') {
            $('#page').hide();
            $('.search_con_three_personal').html('');
            $('.search_con_three_compeny').html('');
            $('.search_con_no_search_content_no').hide();
            $('.search_con_no_search_content').show();
        } else {
            $('.search_con_no_search_content').hide();
            $('.search_con_no_search_content_no').hide();
            var rowCount = SearchPosition.data.length; //条数 
            var pageSi = Math.ceil(rowCount / 8); //总页数
            $('#page').html('');
            $('#page').show();
            if (rowCount == 1) {
                var Count = 2;
            } else {
                var Count = rowCount;
            }
            var nowpage = setPage(1, Count);
            var begin = nowpage * 8 - (nowpage * 8);
            if (nowpage < pageSi) {
                var end = nowpage * 8 - 1;
            } else {
                var end = rowCount - 1;
            }
            SearchPos(begin, end);
        }

        function setPage(nowpage, totalCount) { //nowpage:当前页数  totalCount：数据总条数
            let pageSize = Math.ceil(totalCount / 8); //总页数
            let showSize = pageSize; //显示的页数
            let maxPage = pageSize;
            let oldPage = 1;
            if (showSize <= pageSize) {
                maxPage = showSize;
            }
            if (nowpage > pageSize) {
                nowpage = pageSize;
            }
            if (nowpage < 1) {
                nowpage = 1;
            }
            $("#page").append('<ul><li>&laquo;</li>');
            if (nowpage > Math.ceil(showSize / 2)) {
                if (nowpage <= pageSize - 2 && nowpage >= 3) {
                    for (let i = nowpage - 2; i <= eval(nowpage + "+2"); i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                } else if (nowpage == pageSize - 1) {
                    for (let i = nowpage - 3; i <= eval(nowpage + "+1"); i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                } else {
                    for (let i = nowpage - 4; i <= nowpage; i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                }
            } else {
                for (let i = 1; i <= showSize; i++) {
                    if (i == nowpage) {
                        $("#page ul").append('<li class="active">' + i + '</li>');
                    } else {
                        $("#page ul").append('<li>' + i + '</li>');
                    }
                }
            }
            oldPage = nowpage;
            $("#page ul").append('<li>&raquo;</li></ul>')
            $("#page ul li").click(function() {
                nowpage = $(this).text();
                if ($(this).text() == "«") {
                    $("#page").empty()
                    setPage(Math.ceil(oldPage - 1), totalCount);
                    $(this).siblings("li").removeClass("active");
                } else if ($(this).text() == "»") {
                    $("#page").empty()
                    setPage(Math.ceil(oldPage + 1), totalCount);
                    $(this).siblings("li").removeClass("active");
                } else if (showSize >= pageSize) {
                    $(this).attr("class", "active");
                    $(this).siblings("li").removeClass("active");
                } else if ($(this).text() <= Math.ceil(showSize / 2)) {
                    $(this).attr("class", "active");
                    $(this).siblings("li").removeClass("active");
                } else {
                    $("#page").empty()
                    setPage($(this).text(), totalCount);
                    $(this).siblings("li").removeClass("active");
                }
            })

            return nowpage;

            //如果跳到第1页，则开始就是i=0 (1-1),结束 = 7  (1*8-1)
            //如果跳到第2页，则开始就是i=8 (1*8),结束 = 15 (2*8-1)
            //如果跳到第3页，则开始就是i=16(2*8),结束 = 23 (3*8-1)
        }

        function SearchPos(start, hops) { //职位渲染
            $('.search_con_three_personal').html('');
            $('.search_con_three_compeny').html('');
            for (let i = start; i <= hops; i++) {
                const SearchTetle = `
                    <a href="PositionDetailsPage.html?official_id=${SearchPosition.data[i].official_id}">
                        <div class="personal_con">
                            <div class="personal_con_shang">
                                <div class="personal_con_means">
                                    <div class="personal_con_means_one">
                                        <h5>${SearchPosition.data[i].official}</h5>
                                        <img src="https://19jwshow.oss-cn-shenzhen.aliyuncs.com/recruit/icon/right_icon-location.png" alt="">
                                        <span title="${SearchPosition.data[i].off_area}" class="personal_con_means_one_fc">${SearchPosition.data[i].off_area}</span>
                                        <span>${SearchPosition.data[i].job_money}薪</span>
                                    </div>
                                    <div class="personal_con_means_two">
                                        <span>${SearchPosition.data[i].education}及以上</span>
                                        <span>5 - 8 年</span>
                                        <span>${SearchPosition.data[i].wordweek}天/周</span>
                                    </div>
                                    <div class="personal_con_means_three">
                                        <img src="${SearchPosition.data[i].header}" alt=" ">
                                        <span>${SearchPosition.data[i].username}</span>
                                    </div>
                                </div>
                                <div class="personal_con_company">
                                    <div class="personal_con_company_left">
                                        <p><a href="CompanyIntroduce.html?company_id=${SearchPosition.data[i].company_id}" id="personal_con_Company_name">${SearchPosition.data[i].company_name}</a><span class="personal_con_company_left_span">已上市</span></p>
                                        <p>${SearchPosition.data[i].type}</p>
                                        <p>${SearchPosition.data[i].com_official}人以上</p>
                                    </div>
                                    <div class="personal_con_company_right">
                                        <img src="${SearchPosition.data[i].company_logo}" alt="">
                                    </div>
                                </div>
                            </div>
                            <div class="personal_con_xia">
                                <ul>
                                    <li>${SearchPosition.data[i].requirement}</li>
                                    <li></li>
                                    <li></li>
                                    <li></li>
                                </ul>
                                <ul>
                                    <li>${SearchPosition.data[i].company_welfare}</li>
                                    <li></li>
                                    <li></li>
                                    <li></li>
                                </ul>
                            </div>
                        </div>
                    </a>
                `
                $('.search_con_three_personal').append(SearchTetle);
            }
        };
    }

    function CompanyDefault() {
        var SearchCompany = Interceptor('/searchCompany', 'post'); //搜索公司
        if (SearchCompany.message == '返回所有公司' && SearchCompany.data.data.length == 0) {
            $('#page').hide();
            $('.search_con_three_personal').html('');
            $('.search_con_three_compeny').html('');
            $('.search_con_no_search_content_no').show();
        } else {
            // $('.search_con_three_personal').html('');
            $('.search_con_no_search_content').hide();
            $('.search_con_no_search_content_no').hide();
            var rowCom = SearchCompany.data.data.length; //条数
            var pageSi = Math.ceil(rowCom / 8); //总页数
            $('#page').html('');
            $('#page').show();
            if (rowCom == 1) {
                var roCom = 2;
            } else {
                var roCom = rowCom;
            }
            var nowpage = setPage(1, roCom);
            var begin = nowpage * 8 - (nowpage * 8);
            if (nowpage < pageSi) {
                var end = nowpage * 8 - 1;
            } else {
                var end = rowCom;
            }
            SearchCon(begin, end);
        }

        function setPage(nowpage, totalCount) { //nowpage:当前页数  totalCount：数据总条数
            let pageSize = Math.ceil(totalCount / 8); //总页数
            let showSize = pageSize; //显示的页数
            let maxPage = pageSize;
            let oldPage = 1;
            if (showSize <= pageSize) {
                maxPage = showSize;
            }
            if (nowpage > pageSize) {
                nowpage = pageSize;
            }
            if (nowpage < 1) {
                nowpage = 1;
            }
            $("#page").append('<ul><li>&laquo;</li>');
            if (nowpage > Math.ceil(showSize / 2)) {
                if (nowpage <= pageSize - 2 && nowpage >= 3) {
                    for (let i = nowpage - 2; i <= eval(nowpage + "+2"); i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                } else if (nowpage == pageSize - 1) {
                    for (let i = nowpage - 3; i <= eval(nowpage + "+1"); i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                } else {
                    for (let i = nowpage - 4; i <= nowpage; i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                }
            } else {
                for (let i = 1; i <= showSize; i++) {
                    if (i == nowpage) {
                        $("#page ul").append('<li class="active">' + i + '</li>');
                    } else {
                        $("#page ul").append('<li>' + i + '</li>');
                    }
                }
            }
            oldPage = nowpage;
            $("#page ul").append('<li>&raquo;</li></ul>')
            $("#page ul li").click(function() {
                nowpage = $(this).text();
                if ($(this).text() == "«") {
                    $("#page").empty()
                    setPage(Math.ceil(oldPage - 1), totalCount);
                    $(this).siblings("li").removeClass("active");
                } else if ($(this).text() == "»") {
                    $("#page").empty()
                    setPage(Math.ceil(oldPage + 1), totalCount);
                    $(this).siblings("li").removeClass("active");
                } else if (showSize >= pageSize) {
                    $(this).attr("class", "active");
                    $(this).siblings("li").removeClass("active");
                } else if ($(this).text() <= Math.ceil(showSize / 2)) {
                    $(this).attr("class", "active");
                    $(this).siblings("li").removeClass("active");
                } else {
                    $("#page").empty()
                    setPage($(this).text(), totalCount);
                    $(this).siblings("li").removeClass("active");
                }
            })

            return nowpage;

            //如果跳到第1页，则开始就是i=0 (1-1),结束 = 7  (1*8-1)
            //如果跳到第2页，则开始就是i=8 (1*8),结束 = 15 (2*8-1)
            //如果跳到第3页，则开始就是i=16(2*8),结束 = 23 (3*8-1)
        }

        function SearchCon(start, hops) { //公司渲染
            $('.search_con_three_personal').html('');
            $('.search_con_three_compeny').html('');
            for (let i = start; i < hops; i++) {
                const SearchTetle = `
                        <div class="compeny_con">
                            <div class="compeny_con_shang">
                                <div class="compeny_con_company">
                                    <div class="compeny_con_company_left">
                                        <img src="${SearchCompany.data.data[i].company_logo}" alt="">
                                    </div>
                                    <div class="compeny_con_company_right">
                                        <p>
                                            <a href="CompanyIntroduce.html?company_id=${SearchCompany.data.data[i].company_id}" id="compeny_con_Company_name">${SearchCompany.data.data[i].company_name}</a><span class="compeny_con_company_right_span">已上市</span></p>
                                        <p>${SearchCompany.data.data[i].type}</p>
                                        <p>${SearchCompany.data.data[i].com_official}人以上</p>
                                    </div>
                                </div>
                                <div class="compeny_user">
                                    <img src="${SearchCompany.data.data[i].header}" alt="">
                                    <span>${SearchCompany.data.data[i].username}</span>
                                </div>
                            </div>
                            <div class="compeny_con_xia">
                                <ul>
                                    <li>${SearchCompany.data.data[i].type}</li>
                                    <li></li>
                                    <li></li>
                                    <li></li>
                                </ul>
                                <ul>
                                    <li>${SearchCompany.data.data[i].company_welfare}</li>
                                    <li></li>
                                    <li></li>
                                    <li></li>
                                </ul>
                            </div>
                        </div>
                    `
                $('.search_con_three_compeny').append(SearchTetle);
            }
        };
    }

    function CompanyDefaultoff() {
        let NavSearch = $('#nav_search').val(); //必
        let SearchType = $('.search_con_type_con_span').text();
        let SearchProLevel = $('.search_con_add_con_span').text(); //传省
        let SearchMunLevel = $('.search_con_jobadd_left > span').text(); //传市
        let SearchCoulevel = $('.search_con_jobadd_town_left > span').text(); //传镇
        if (SearchType == "职业类型") {
            var type = "";
        } else {
            var type = SearchType;
        }
        if (SearchProLevel == "地区") {
            var shen = "";
        } else {
            var shen = SearchProLevel;
        }
        if (SearchMunLevel == "全国") {
            var shi = "";
        } else {
            var shi = SearchMunLevel;
        }
        if (SearchCoulevel == "不限") {
            var zhen = "";
        } else {
            var zhen = SearchCoulevel;
        }
        let SearchCompany = Interceptor('/searchCompany', 'post', {
            'searchValue': NavSearch, //输入搜索内容 搜索学历，职位，公司
            'urban': shi,
            'town': zhen,
            'province': shen,
            'searchType': type
        });

        if (SearchCompany.message == '没有该内容') {
            $('#page').hide();
            $('.search_con_three_personal').html('');
            $('.search_con_three_compeny').html('');
            $('.search_con_no_search_content_no').hide();
            $('.search_con_no_search_content').show();
        } else {
            $('.search_con_three_personal').html('');
            $('.search_con_no_search_content').hide();
            $('.search_con_no_search_content_no').hide();
            var rowCom = SearchCompany.data.data.length; //条数
            var pageSi = Math.ceil(rowCom / 8); //总页数
            $('#page').html('');
            $('#page').show();
            if (rowCom == 1) {
                var roCom = 2;
            } else {
                var roCom = rowCom;
            }
            var nowpage = setPage(1, roCom);
            var begin = nowpage * 8 - (nowpage * 8);
            if (nowpage < pageSi) {
                var end = nowpage * 8 - 1;
            } else {
                var end = rowCom - 1;
            }
            SearchCon(begin, end);
        }

        function setPage(nowpage, totalCount) { //nowpage:当前页数  totalCount：数据总条数
            let pageSize = Math.ceil(totalCount / 8); //总页数
            let showSize = pageSize; //显示的页数
            let maxPage = pageSize;
            let oldPage = 1;
            if (showSize <= pageSize) {
                maxPage = showSize;
            }
            if (nowpage > pageSize) {
                nowpage = pageSize;
            }
            if (nowpage < 1) {
                nowpage = 1;
            }
            $("#page").append('<ul><li>&laquo;</li>');
            if (nowpage > Math.ceil(showSize / 2)) {
                if (nowpage <= pageSize - 2 && nowpage >= 3) {
                    for (let i = nowpage - 2; i <= eval(nowpage + "+2"); i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                } else if (nowpage == pageSize - 1) {
                    for (let i = nowpage - 3; i <= eval(nowpage + "+1"); i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                } else {
                    for (let i = nowpage - 4; i <= nowpage; i++) {
                        if (i == nowpage) {
                            $("#page ul").append('<li class="active">' + i + '</li>');
                        } else {
                            $("#page ul").append('<li>' + i + '</li>');
                        }
                    }
                }
            } else {
                for (let i = 1; i <= showSize; i++) {
                    if (i == nowpage) {
                        $("#page ul").append('<li class="active">' + i + '</li>');
                    } else {
                        $("#page ul").append('<li>' + i + '</li>');
                    }
                }
            }
            oldPage = nowpage;
            $("#page ul").append('<li>&raquo;</li></ul>')
            $("#page ul li").click(function() {
                nowpage = $(this).text();
                if ($(this).text() == "«") {
                    $("#page").empty()
                    setPage(Math.ceil(oldPage - 1), totalCount);
                    $(this).siblings("li").removeClass("active");
                } else if ($(this).text() == "»") {
                    $("#page").empty()
                    setPage(Math.ceil(oldPage + 1), totalCount);
                    $(this).siblings("li").removeClass("active");
                } else if (showSize >= pageSize) {
                    $(this).attr("class", "active");
                    $(this).siblings("li").removeClass("active");
                } else if ($(this).text() <= Math.ceil(showSize / 2)) {
                    $(this).attr("class", "active");
                    $(this).siblings("li").removeClass("active");
                } else {
                    $("#page").empty()
                    setPage($(this).text(), totalCount);
                    $(this).siblings("li").removeClass("active");
                }
            })

            return nowpage;
        }

        function SearchCon(start, hops) { //公司渲染
            $('.search_con_three_personal').html('');
            $('.search_con_three_compeny').html('');
            for (let i = start; i <= hops; i++) {
                const SearchTetle = `
                        <div class="compeny_con">
                            <div class="compeny_con_shang">
                                <div class="compeny_con_company">
                                    <div class="compeny_con_company_left">
                                        <img src="${SearchCompany.data.data[i].company_logo}" alt="">
                                    </div>
                                    <div class="compeny_con_company_right">
                                        <p>
                                            <a href="CompanyIntroduce.html?.company_id=${SearchCompany.data.data[i].company_id}" id="compeny_con_Company_name">${SearchCompany.data.data[i].company_name}</a><span class="compeny_con_company_right_span">已上市</span></p>
                                        <p>${SearchCompany.data.data[i].type}</p>
                                        <p>${SearchCompany.data.data[i].com_official}人以上</p>
                                    </div>
                                </div>
                                <div class="compeny_user">
                                    <img src="${SearchCompany.data.data[i].header}" alt="">
                                    <span>${SearchCompany.data.data[i].username}</span>
                                </div>
                            </div>
                            <div class="compeny_con_xia">
                                <ul>
                                    <li>${SearchCompany.data.data[i].type}</li>
                                    <li></li>
                                    <li></li>
                                    <li></li>
                                </ul>
                                <ul>
                                    <li>${SearchCompany.data.data[i].company_welfare}</li>
                                    <li></li>
                                    <li></li>
                                    <li></li>
                                </ul>
                            </div>
                        </div>
                    `
                $('.search_con_three_compeny').append(SearchTetle);
            }
        };
    }
});